#include "esphome.h"
#include "Wire.h"

class MyEEPROMComponent : public Component {
 public:
  void setup() override {
    Wire.begin();
    ESP_LOGD("custom", "EEPROM initialized");
  }

  void write_data(uint8_t address, int value) {
    Wire.beginTransmission(0x50);
    Wire.write(address);
    Wire.write(value >> 8);
    Wire.write(value & 0xFF);
    Wire.endTransmission();
    delay(5);
  }

  int read_data(uint8_t address) {
    Wire.beginTransmission(0x50);
    Wire.write(address);
    Wire.endTransmission();
    Wire.requestFrom(0x50, 2);
    int value = Wire.read() << 8;
    value |= Wire.read();
    return value;
  }
};
